<?php
namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;


class Content extends Model
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;
    protected $createTime = "add_time";
    protected $updateTime ="last_time";
    public function getAddTimeAttr($value)
    {
        return date("Y-m-d",$value);
    }
    public function user()
    {
        return $this->hasOne(User::class,"id","uid");
    }

    public function cate()
    {
        return $this->hasOne(ArticleCate::class,"id","cate_id");
    }

    public function video()
    {
        return $this->hasOne(Video::class,"contentid","id")->bind([
            "video_id"=>"id"
        ]);
    }
    public function v()
    {
        return $this->hasOne(Video::class,"contentid","id");
    }

    public function log()
    {
        return $this->hasMany(ArticlePv::class,"aid","id")->order('id DESC')->limit(10);
    }
    public function article()
    {
        return $this->hasOne(Article::class,"contentid","id")
            ->order("id DESC");
    }
    public function images()
    {
        return $this->hasOne(Images::class,"contentid","id");
    }

    public function mod()
    {
        return $this->hasOne(Mod::class,"id","model_id");
    }

    public function fav()
    {
        return $this->hasOne(ArticleFav::class,"cid","id");
    }

    //查找子集
    public function child()
    {
        return $this->hasMany(Content::class,"pid","id")->field("id,title,pid");
    }



}
